﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Model
{
    /// <summary>
    /// 事件案例学习
    /// </summary>
    public class EventStudy
    {
        // 第一步: 声明一个委托

        // 第二步; 声明一个事件

        // 第三步; 将要执行的函数绑定到委托

        // 第四步; 触发/执行 事件 

        //1
        public delegate void DelegateDisaster(string ClassRomName);
        //2
        public event DelegateDisaster EventDisaster;
        //3
        //DelegateDisaster delegateDisaster = () => { };
        public void Run(string ClassRomName)
        {
            Console.WriteLine(ClassRomName + "正在避灾");
        }

        public void Stop(string ClassRomName) 
        {
            Console.WriteLine(ClassRomName + " 到达指定避难场所");
        }

        public void Do()
        {
            //匿名函数写法
            EventDisaster += new DelegateDisaster((ClassRomName) => {
                Console.WriteLine(ClassRomName + "正在避灾");
            });
            EventDisaster += new DelegateDisaster((ClassRomName) =>
            {
                Console.WriteLine(ClassRomName + "正在下楼梯");
            });
            EventDisaster += new DelegateDisaster((ClassRomName) =>
            {
                Console.WriteLine(ClassRomName + "正在前往安全屋");
            });
            EventDisaster += new DelegateDisaster((ClassRomName) =>
            {
                Console.WriteLine(ClassRomName + "天塌地陷");
            });
            //共名函数写法
            EventDisaster += new DelegateDisaster(this.Run);
            EventDisaster += new DelegateDisaster(this.Stop);
            EventDisaster("T310");
        }
    }
}
